package glossos.search;

import java.util.LinkedHashMap;
import java.util.Map;

public class LRUCache<K,V> {
	private final LinkedHashMap<K,V> map;
	private final int cacheSize;

	public LRUCache (final int cacheSize) {
		this.cacheSize = cacheSize;
		map = new LinkedHashMap<K,V>(cacheSize, 0.75F, true) {
			private static final long serialVersionUID = 1L;
			@Override protected boolean removeEldestEntry (Map.Entry<K,V> eldest) {
				return size() > LRUCache.this.cacheSize; 
			}
		}; 
	}

	public boolean contains(K key){
		return map.containsKey(key);
	}
	
	public V get(K key) {
		return map.get(key); 
	}

	public void put(K key, V value) {
		map.put(key,value); 
	}
}